package com.tanhua.manager.controller;

import com.tanhua.domain.db.UserFreeze;
import com.tanhua.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {


    @Autowired
    private UserService userService;


    /**
     * 动态通过
     * @param publishIds 动态Id
     * @return
     */

    @PostMapping("/messages/pass")
    public ResponseEntity pass(@RequestBody String[] publishIds){
        return userService.pass(publishIds);

    }

    /**
     *
     * @param publishIds 动态Id
     * @return
     */
    @PostMapping("/messages/reject")
    public ResponseEntity reject(@RequestBody String[] publishIds){
        return userService.reject(publishIds);
    }

    @GetMapping(value = "/users",name = "分页查询用户")
    public ResponseEntity queryUsers(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10")  Integer pagesize,
                                     Long id,
                                     String nickname,
                                     String city

    ){
        return    userService.queryUsers(page,pagesize,id,nickname,city);

    }


    @GetMapping(value = "/users/{userID}",name = "查询指定用户")
    public ResponseEntity queryUserById(@PathVariable("userID") Long userId){
        return    userService.queryUserById(userId);

    }

    @GetMapping(value = "/videos",name = "查询指定用户的小视频列表")
    public ResponseEntity queryVideosByUserId(@RequestParam(defaultValue = "1") Integer page,
                                              @RequestParam(defaultValue = "10")  Integer pagesize,
                                              Long uid){
        return    userService.queryVideosByUserId(page,pagesize,uid);

    }

    @GetMapping(value = "/messages",name = "查询指定用户的圈子列表")
    public ResponseEntity queryPublishByUserId(@RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10")  Integer pagesize,
                                               Long uid,Integer state){
        return    userService.queryPublishByUserId(page,pagesize,uid,state);
    }

    @GetMapping(value = "/messages/{id}",name = "指定的圈子信息")
    public ResponseEntity queryPublishById(@PathVariable("id") String publishId){
        return   userService.queryPublishById(publishId);
    }

    @GetMapping(value = "/messages/comments",name = "查询指定的圈子的评论列表")
    public ResponseEntity queryPublishComments(@RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10")  Integer pagesize,
                                               String messageID){
        return   userService.queryPublishComments(page,pagesize,messageID);
    }
    @PostMapping(value = "/users/freeze",name = "冻结用户")
    public ResponseEntity freeze(@RequestBody Map<String,Object> map){
        Long userId = Long.parseLong(map.get("userId").toString());
        Integer freezingTime = Integer.valueOf(map.get("freezingTime").toString());
        Integer freezingRange = Integer.valueOf(map.get("freezingRange").toString());
        String reasonsForFreezing = map.get("reasonsForFreezing").toString();
        String frozenRemarks = map.get("frozenRemarks").toString();



        userService.freeze(userId,freezingTime,freezingRange,reasonsForFreezing,frozenRemarks);
        return ResponseEntity.ok("成功");

    }
    @PostMapping(value = "/users/unfreeze",name = "用户解冻")
    public ResponseEntity unfreeze(@RequestBody Map<String,Object> map){
        Long userId=   Long.parseLong(map.get("userId").toString());
        String reasonsForThawing = map.get("reasonsForThawing").toString();
        String frozenRemarks = map.get("frozenRemarks").toString();
        userService.unfreeze(userId,reasonsForThawing,frozenRemarks);
        return ResponseEntity.ok("成功");

    }


}